From: Alex Williamson Date: Fri, 21 Sep 2007 17:03:54 +0000 (-0600) Subject: [IA64] debug_op hypercall and debug points X-Git-Tag: archive/raspbian/4.8.0-1+rpi1~1^2~14960 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=b68fe168b1541bdf07c551deec60f9f1600b2233;p=xen.git [IA64] debug_op hypercall and debug points Add debug_op hypercall. Add many debug points. Signed-off-by: Tristan Gingold --- diff --git a/xen/arch/ia64/linux-xen/entry.S b/xen/arch/ia64/linux-xen/entry.S index 9f008c6841..ecb16b1793 100644 --- a/xen/arch/ia64/linux-xen/entry.S +++ b/xen/arch/ia64/linux-xen/entry.S @@ -1535,7 +1535,7 @@ ia64_hypercall_table: data8 do_ni_hypercall /* */ data8 do_dom0vp_op /* dom0vp_op */ data8 do_pirq_guest_eoi /* arch_1 */ - data8 do_ni_hypercall /* arch_2 */ /* 50 */ + data8 do_ia64_debug_op /* arch_2 */ /* 50 */ data8 do_ni_hypercall /* arch_3 */ data8 do_ni_hypercall /* arch_4 */ data8 do_ni_hypercall /* arch_5 */ diff --git a/xen/arch/ia64/vmx/vmx_interrupt.c b/xen/arch/ia64/vmx/vmx_interrupt.c index ce3d1e6745..b9da63ccac 100644 --- a/xen/arch/ia64/vmx/vmx_interrupt.c +++ b/xen/arch/ia64/vmx/vmx_interrupt.c @@ -24,6 +24,7 @@ #include #include #include +#include /* SDM vol2 5.5 - IVA based interruption handling */ #define INITIAL_PSR_VALUE_AT_INTERRUPTION 0x0000001808028034 @@ -107,6 +108,9 @@ inject_guest_interruption(VCPU *vcpu, u64 vec) viva = vmx_vcpu_get_iva(vcpu); regs->cr_iip = viva + vec; + + debugger_event(vec == IA64_EXTINT_VECTOR ? + XEN_IA64_DEBUG_ON_EXTINT : XEN_IA64_DEBUG_ON_EXCEPT); } diff --git a/xen/arch/ia64/vmx/vmx_phy_mode.c b/xen/arch/ia64/vmx/vmx_phy_mode.c index 810e11fb41..3992ceca54 100644 --- a/xen/arch/ia64/vmx/vmx_phy_mode.c +++ b/xen/arch/ia64/vmx/vmx_phy_mode.c @@ -28,6 +28,7 @@ #include #include #include +#include static const int valid_mm_mode[8] = { GUEST_PHYS, /* (it, dt, rt) -> (0, 0, 0) */ @@ -300,6 +301,7 @@ check_mm_mode_switch (VCPU *vcpu, IA64_PSR old_psr, IA64_PSR new_psr) (old_psr.rt != new_psr.rt ) ) { switch_mm_mode (vcpu, old_psr, new_psr); + debugger_event(XEN_IA64_DEBUG_ON_MMU); } return; diff --git a/xen/arch/ia64/vmx/vmx_vcpu.c b/xen/arch/ia64/vmx/vmx_vcpu.c index 8014ce31d0..acef1db957 100644 --- a/xen/arch/ia64/vmx/vmx_vcpu.c +++ b/xen/arch/ia64/vmx/vmx_vcpu.c @@ -135,6 +135,13 @@ vmx_vcpu_set_psr(VCPU *vcpu, unsigned long value) if (FP_PSR(vcpu) & IA64_PSR_DFH) regs->cr_ipsr |= IA64_PSR_DFH; + if (unlikely(vcpu->domain->debugger_attached)) { + if (vcpu->domain->arch.debug_flags & XEN_IA64_DEBUG_FORCE_SS) + regs->cr_ipsr |= IA64_PSR_SS; + if (vcpu->domain->arch.debug_flags & XEN_IA64_DEBUG_FORCE_DB) + regs->cr_ipsr |= IA64_PSR_DB; + } + check_mm_mode_switch(vcpu, old_psr, new_psr); return ; } diff --git a/xen/arch/ia64/vmx/vmx_virt.c b/xen/arch/ia64/vmx/vmx_virt.c index a195c291f1..626bd23744 100644 --- a/xen/arch/ia64/vmx/vmx_virt.c +++ b/xen/arch/ia64/vmx/vmx_virt.c @@ -30,6 +30,7 @@ #include #include #include +#include #ifdef BYPASS_VMAL_OPCODE static void @@ -203,6 +204,11 @@ static IA64FAULT vmx_emul_rfi(VCPU *vcpu, INST64 inst) } #endif // CHECK_FAULT + if (debugger_event(XEN_IA64_DEBUG_ON_RFI)) { + raise_softirq(SCHEDULE_SOFTIRQ); + do_softirq(); + } + regs=vcpu_regs(vcpu); vpsr.val=regs->cr_ipsr; if ( vpsr.is == 1 ) { @@ -279,6 +285,8 @@ static IA64FAULT vmx_emul_ptc_l(VCPU *vcpu, INST64 inst) } #endif // VMAL_NO_FAULT_CHECK + debugger_event(XEN_IA64_DEBUG_ON_TC); + return vmx_vcpu_ptc_l(vcpu,r3,bits(r2,2,7)); } @@ -338,6 +346,8 @@ static IA64FAULT vmx_emul_ptc_g(VCPU *vcpu, INST64 inst) } #endif // VMAL_NO_FAULT_CHECK + debugger_event(XEN_IA64_DEBUG_ON_TC); + return vmx_vcpu_ptc_g(vcpu,r3,bits(r2,2,7)); } @@ -372,6 +382,8 @@ static IA64FAULT vmx_emul_ptc_ga(VCPU *vcpu, INST64 inst) } #endif // VMAL_NO_FAULT_CHECK + debugger_event(XEN_IA64_DEBUG_ON_TC); + return vmx_vcpu_ptc_ga(vcpu,r3,bits(r2,2,7)); } @@ -414,6 +426,9 @@ static IA64FAULT vmx_emul_ptr_d(VCPU *vcpu, INST64 inst) u64 r2,r3; if ( ptr_fault_check(vcpu, inst, &r2, &r3 ) == IA64_FAULT ) return IA64_FAULT; + + debugger_event(XEN_IA64_DEBUG_ON_TR); + return vmx_vcpu_ptr_d(vcpu,r3,bits(r2,2,7)); } @@ -422,6 +437,9 @@ static IA64FAULT vmx_emul_ptr_i(VCPU *vcpu, INST64 inst) u64 r2,r3; if ( ptr_fault_check(vcpu, inst, &r2, &r3 ) == IA64_FAULT ) return IA64_FAULT; + + debugger_event(XEN_IA64_DEBUG_ON_TR); + return vmx_vcpu_ptr_i(vcpu,r3,bits(r2,2,7)); } @@ -633,6 +651,8 @@ static IA64FAULT vmx_emul_itr_d(VCPU *vcpu, INST64 inst) return IA64_FAULT; } + debugger_event(XEN_IA64_DEBUG_ON_TR); + return (vmx_vcpu_itr_d(vcpu, slot, pte, itir, ifa)); } @@ -699,6 +719,8 @@ static IA64FAULT vmx_emul_itr_i(VCPU *vcpu, INST64 inst) return IA64_FAULT; } + debugger_event(XEN_IA64_DEBUG_ON_TR); + return vmx_vcpu_itr_i(vcpu, slot, pte, itir, ifa); } @@ -760,6 +782,8 @@ static IA64FAULT vmx_emul_itc_d(VCPU *vcpu, INST64 inst) return IA64_FAULT; } + debugger_event(XEN_IA64_DEBUG_ON_TC); + return vmx_vcpu_itc_d(vcpu, pte, itir, ifa); } @@ -771,6 +795,8 @@ static IA64FAULT vmx_emul_itc_i(VCPU *vcpu, INST64 inst) return IA64_FAULT; } + debugger_event(XEN_IA64_DEBUG_ON_TC); + return vmx_vcpu_itc_i(vcpu, pte, itir, ifa); } @@ -1425,6 +1451,9 @@ if ( (cause == 0xff && opcode == 0x1e000000000) || cause == 0 ) { #else inst.inst=opcode; #endif /* BYPASS_VMAL_OPCODE */ + + debugger_event(XEN_IA64_DEBUG_ON_PRIVOP); + /* * Switch to actual virtual rid in rr0 and rr4, * which is required by some tlb related instructions. diff --git a/xen/arch/ia64/xen/faults.c b/xen/arch/ia64/xen/faults.c index 6ab41dd261..0213873ca6 100644 --- a/xen/arch/ia64/xen/faults.c +++ b/xen/arch/ia64/xen/faults.c @@ -104,6 +104,9 @@ static void reflect_interruption(unsigned long isr, struct pt_regs *regs, PSCB(v, interrupt_collection_enabled) = 0; perfc_incra(slow_reflect, vector >> 8); + + debugger_event(vector == IA64_EXTINT_VECTOR ? + XEN_IA64_DEBUG_ON_EXTINT : XEN_IA64_DEBUG_ON_EXCEPT); } void reflect_event(void) @@ -151,6 +154,8 @@ void reflect_event(void) PSCB(v, vpsr_dfh) = 0; v->vcpu_info->evtchn_upcall_mask = 1; PSCB(v, interrupt_collection_enabled) = 0; + + debugger_event(XEN_IA64_DEBUG_ON_EVENT); } static int handle_lazy_cover(struct vcpu *v, struct pt_regs *regs) @@ -670,7 +675,7 @@ ia64_handle_reflection(unsigned long ifa, struct pt_regs *regs, break; case 29: vector = IA64_DEBUG_VECTOR; - if (debugger_trap_entry(vector,regs)) + if (debugger_kernel_event(regs, XEN_IA64_DEBUG_ON_KERN_DEBUG)) return; break; case 30: @@ -708,12 +713,12 @@ ia64_handle_reflection(unsigned long ifa, struct pt_regs *regs, break; case 35: vector = IA64_TAKEN_BRANCH_TRAP_VECTOR; - if (debugger_trap_entry(vector,regs)) + if (debugger_kernel_event(regs, XEN_IA64_DEBUG_ON_KERN_TBRANCH)) return; break; case 36: vector = IA64_SINGLE_STEP_TRAP_VECTOR; - if (debugger_trap_entry(vector,regs)) + if (debugger_kernel_event(regs, XEN_IA64_DEBUG_ON_KERN_SSTEP)) return; break; diff --git a/xen/arch/ia64/xen/fw_emul.c b/xen/arch/ia64/xen/fw_emul.c index 13bdb71c3f..8b00e62ea4 100644 --- a/xen/arch/ia64/xen/fw_emul.c +++ b/xen/arch/ia64/xen/fw_emul.c @@ -36,6 +36,7 @@ #include #include #include +#include static DEFINE_SPINLOCK(efi_time_services_lock); @@ -137,6 +138,8 @@ sal_emulator (long index, unsigned long in1, unsigned long in2, long r11 = 0; long status; + debugger_event(XEN_IA64_DEBUG_ON_SAL); + status = 0; switch (index) { case SAL_FREQ_BASE: @@ -595,6 +598,8 @@ xen_pal_emulator(unsigned long index, u64 in1, u64 in2, u64 in3) if (unlikely(running_on_sim)) return pal_emulator_static(index); + debugger_event(XEN_IA64_DEBUG_ON_PAL); + // pal code must be mapped by a TR when pal is called, however // calls are rare enough that we will map it lazily rather than // at every context switch @@ -1241,6 +1246,8 @@ efi_emulator (struct pt_regs *regs, IA64FAULT *fault) struct vcpu *v = current; efi_status_t status; + debugger_event(XEN_IA64_DEBUG_ON_EFI); + *fault = IA64_NO_FAULT; switch (regs->r2) { diff --git a/xen/arch/ia64/xen/hypercall.c b/xen/arch/ia64/xen/hypercall.c index cfb8893439..cf80c54457 100644 --- a/xen/arch/ia64/xen/hypercall.c +++ b/xen/arch/ia64/xen/hypercall.c @@ -493,3 +493,35 @@ long do_callback_op(int cmd, XEN_GUEST_HANDLE(void) arg) return ret; } + +unsigned long +do_ia64_debug_op(unsigned long cmd, unsigned long domain, + XEN_GUEST_HANDLE(xen_ia64_debug_op_t) u_debug_op) +{ + xen_ia64_debug_op_t curop, *op = &curop; + struct domain *d; + long ret = 0; + + if (!IS_PRIV(current->domain)) + return -EPERM; + if (copy_from_guest(op, u_debug_op, 1)) + return -EFAULT; + d = rcu_lock_domain_by_id(domain); + if (d == NULL) + return -ESRCH; + + switch (cmd) { + case XEN_IA64_DEBUG_OP_SET_FLAGS: + d->arch.debug_flags = op->flags; + break; + case XEN_IA64_DEBUG_OP_GET_FLAGS: + op->flags = d->arch.debug_flags; + if (copy_to_guest(u_debug_op, op, 1)) + ret = -EFAULT; + break; + default: + ret = -ENOSYS; + } + rcu_unlock_domain(d); + return ret; +} diff --git a/xen/arch/ia64/xen/mm.c b/xen/arch/ia64/xen/mm.c index 6399b5a2fd..8d8cc710d7 100644 --- a/xen/arch/ia64/xen/mm.c +++ b/xen/arch/ia64/xen/mm.c @@ -181,6 +181,7 @@ #include #include #include +#include static void domain_page_flush_and_put(struct domain* d, unsigned long mpaddr, volatile pte_t* ptep, pte_t old_pte, @@ -763,6 +764,8 @@ unsigned long lookup_domain_mpa(struct domain *d, unsigned long mpaddr, d->domain_id, mpaddr, d->arch.convmem_end); } + debugger_event (XEN_IA64_DEBUG_ON_BAD_MPA); + if (entry != NULL) p2m_entry_set(entry, NULL, __pte(0)); //XXX This is a work around until the emulation memory access to a region diff --git a/xen/arch/ia64/xen/privop.c b/xen/arch/ia64/xen/privop.c index b114904b65..a7a91071f4 100644 --- a/xen/arch/ia64/xen/privop.c +++ b/xen/arch/ia64/xen/privop.c @@ -622,6 +622,8 @@ static IA64FAULT priv_handle_op(VCPU * vcpu, REGS * regs) } else if (ia64_get_cpl(ipsr) > CONFIG_CPL0_EMUL) return IA64_ILLOP_FAULT; + debugger_event(XEN_IA64_DEBUG_ON_PRIVOP); + switch (slot_type) { case M: if (inst.generic.major == 0) { @@ -785,6 +787,9 @@ int ia64_hyperprivop(unsigned long iim, REGS * regs) return 1; } perfc_incra(slow_hyperprivop, iim); + + debugger_event(XEN_IA64_DEBUG_ON_PRIVOP); + switch (iim) { case HYPERPRIVOP_RFI: vcpu_rfi(v); diff --git a/xen/include/asm-ia64/debugger.h b/xen/include/asm-ia64/debugger.h index 747e5a79cf..7200485d3f 100644 --- a/xen/include/asm-ia64/debugger.h +++ b/xen/include/asm-ia64/debugger.h @@ -83,16 +83,31 @@ static inline int debugger_trap_fatal( #define debugger_trap_immediate() ((void)0) #endif -static inline int debugger_trap_entry( - unsigned int vector, struct cpu_user_regs *regs) +static inline int debugger_event(unsigned long event) { struct vcpu *v = current; + struct domain *d = v->domain; - if (guest_kernel_mode(regs) && v->domain->debugger_attached) { + if (unlikely (d->debugger_attached && (d->arch.debug_flags & event))) { + d->arch.debug_event = event; domain_pause_for_debugger(); return 1; } + return 0; +} +static inline int debugger_kernel_event( + struct cpu_user_regs *regs, unsigned long event) +{ + struct vcpu *v = current; + struct domain *d = v->domain; + + if (unlikely(d->debugger_attached && (d->arch.debug_flags & event) + && guest_kernel_mode(regs))) { + d->arch.debug_event = event; + domain_pause_for_debugger(); + return 1; + } return 0; } diff --git a/xen/include/asm-ia64/domain.h b/xen/include/asm-ia64/domain.h index 77b2d8b827..1ee75e8768 100644 --- a/xen/include/asm-ia64/domain.h +++ b/xen/include/asm-ia64/domain.h @@ -181,6 +181,12 @@ struct arch_domain { struct opt_feature opt_feature; + /* Debugging flags. See arch-ia64.h for bits definition. */ + unsigned int debug_flags; + + /* Reason of debugging break. */ + unsigned int debug_event; + #ifdef CONFIG_XEN_IA64_TLB_TRACK struct tlb_track* tlb_track; #endif diff --git a/xen/include/asm-ia64/vmx.h b/xen/include/asm-ia64/vmx.h index a217b05165..ed7171ff82 100644 --- a/xen/include/asm-ia64/vmx.h +++ b/xen/include/asm-ia64/vmx.h @@ -39,8 +39,6 @@ extern void vmx_io_assist(struct vcpu *v); extern int ia64_hypercall (struct pt_regs *regs); extern void vmx_save_state(struct vcpu *v); extern void vmx_load_state(struct vcpu *v); -extern void show_registers(struct pt_regs *regs); -#define show_execution_state show_registers extern unsigned long __gpfn_to_mfn_foreign(struct domain *d, unsigned long gpfn); extern void sync_split_caches(void); extern void set_privileged_operation_isr (struct vcpu *vcpu,int inst); diff --git a/xen/include/public/arch-ia64.h b/xen/include/public/arch-ia64.h index e3ee678b13..29e2fafd1c 100644 --- a/xen/include/public/arch-ia64.h +++ b/xen/include/public/arch-ia64.h @@ -293,6 +293,8 @@ struct ia64_tr_entry { unsigned long vadr; unsigned long rid; }; +typedef struct ia64_tr_entry ia64_tr_entry_t; +DEFINE_XEN_GUEST_HANDLE(ia64_tr_entry_t); struct vcpu_tr_regs { struct ia64_tr_entry itrs[8]; @@ -556,6 +558,82 @@ struct xen_ia64_boot_param { /* Fast and light hypercalls. */ #define __HYPERVISOR_ia64_fast_eoi __HYPERVISOR_arch_1 +/* Extra debug features. */ +#define __HYPERVISOR_ia64_debug_op __HYPERVISOR_arch_2 + +/* Set/Get extra conditions to break. */ +#define XEN_IA64_DEBUG_OP_SET_FLAGS 1 +#define XEN_IA64_DEBUG_OP_GET_FLAGS 2 + +/* Break on kernel single step. */ +#define XEN_IA64_DEBUG_ON_KERN_SSTEP (1 << 0) + +/* Break on kernel debug (breakpoint or watch point). */ +#define XEN_IA64_DEBUG_ON_KERN_DEBUG (1 << 1) + +/* Break on kernel taken branch. */ +#define XEN_IA64_DEBUG_ON_KERN_TBRANCH (1 << 2) + +/* Break on interrupt injection. */ +#define XEN_IA64_DEBUG_ON_EXTINT (1 << 3) + +/* Break on interrupt injection. */ +#define XEN_IA64_DEBUG_ON_EXCEPT (1 << 4) + +/* Break on event injection. */ +#define XEN_IA64_DEBUG_ON_EVENT (1 << 5) + +/* Break on privop/virtualized instruction (slow path only). */ +#define XEN_IA64_DEBUG_ON_PRIVOP (1 << 6) + +/* Break on emulated PAL call (at entry). */ +#define XEN_IA64_DEBUG_ON_PAL (1 << 7) + +/* Break on emulated SAL call (at entry). */ +#define XEN_IA64_DEBUG_ON_SAL (1 << 8) + +/* Break on emulated EFI call (at entry). */ +#define XEN_IA64_DEBUG_ON_EFI (1 << 9) + +/* Break on rfi emulation (slow path only, before exec). */ +#define XEN_IA64_DEBUG_ON_RFI (1 << 10) + +/* Break on address translation switch. */ +#define XEN_IA64_DEBUG_ON_MMU (1 << 11) + +/* Break on bad guest physical address. */ +#define XEN_IA64_DEBUG_ON_BAD_MPA (1 << 12) + +/* Force psr.ss bit. */ +#define XEN_IA64_DEBUG_FORCE_SS (1 << 13) + +/* Force psr.db bit. */ +#define XEN_IA64_DEBUG_FORCE_DB (1 << 14) + +/* Break on ITR/PTR. */ +#define XEN_IA64_DEBUG_ON_TR (1 << 15) + +/* Break on ITC/PTC.L/PTC.G/PTC.GA. */ +#define XEN_IA64_DEBUG_ON_TC (1 << 16) + +/* Get translation cache. */ +#define XEN_IA64_DEBUG_OP_GET_TC 3 + +/* Translate virtual address to guest physical address. */ +#define XEN_IA64_DEBUG_OP_TRANSLATE 4 + +#ifndef __ASSEMBLY__ +union xen_ia64_debug_op { + uint64_t flags; + struct xen_ia64_debug_vtlb { + uint64_t nbr; /* IN/OUT */ + XEN_GUEST_HANDLE_64(ia64_tr_entry_t) tr; /* IN/OUT */ + } vtlb; +}; +typedef union xen_ia64_debug_op xen_ia64_debug_op_t; +DEFINE_XEN_GUEST_HANDLE(xen_ia64_debug_op_t); +#endif /* __ASSEMBLY__ */ + /* Xencomm macros. */ #define XENCOMM_INLINE_MASK 0xf800000000000000UL #define XENCOMM_INLINE_FLAG 0x8000000000000000UL